import Vue from 'vue'
import Vuex from 'vuex'
import Cookies from 'js-cookie'
import jwt from 'jsonwebtoken'
//Vuex保存数据后，刷新页面数据就会丢失
//把数据保存在浏览器本地中
//这里使用cookie
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    loginUserData:{},
    token:{}
  },
  mutations: {
    setLoginUserData(state,data){
      Cookies.set('loginUserData',data);
      state.loginUserData = data
    },
    setToken(state,data){
      Cookies.set('token',data);
      state.token = data
    }
  },
  getters:{
    getToken(){
      return Cookies.get('token');
    },
    getLoginUserDatan(){
      let token = Cookies.get('token');
      return jwt.decode(token);
    }
  },
  actions: {
  },
  modules: {
  }
})
